<html><head><title>NewMap</title></head>
<body bgcolor="#FFFFDF" link="#009999" vlink="#006666" alink="#006666">
<font face="Arial" size="2"><p align="center"><b><font size="5">NewMap</font></b></p>

<br><b>Syntax</b><blockquote><pre><font face="Courier New, Courier, mono"size="2"><b><font color="#006666">NewMap</font></b> name.&#060;type&#062;([Slots])      
</font></pre></blockquote>
<b>Description</b><br><blockquote>


<b><font color="#006666">NewMap</font></b> allows to declare a new map, also known as hashtable or dictionary. It allows to quickly reference an element based 
on a key. Each key in the map are unique, which means it can't have two distinct elements with the same key. There are no element limits, 
so there can be as many as needed. A map can have any <a href="../reference/variables.html">standard</a> or <a href="../reference/structures.html">structured</a> type. 
To view all commands used to manage maps, see the <a href="../map/index.html">Map</a> library. <br>
<br>
When using a new key for an assignment, a new element is automatically added to the map. If another element with the same key is already 
in the map, it will be replaced by the new one. Once an element as been accessed or created, it becomes the current element of the map, 
and further access to this element can be done without specify the key. This is useful when using structured map, as no more element 
lookup is needed to access different structure field.<br>
<br>
New maps are always locals by default, so <a href="../reference/global.html">Global</a> or <a href="../reference/shared.html">Shared</a> commands 
have to be used if a map declared in the main source need to be used in procedures. 
It is also possible to pass a map as parameter to a <a href="../reference/procedures.html">procedure</a> by using the 
keyword <b><font color="#006666">Map</font></b>. 
<br>
<br>
For fast swapping of map elements the <a href="../reference/others.html">Swap</a> keyword is available. 
<br>
<br>
The optional 'Slots' parameter defines how much slots the map will have have to store its elements. The more slots is has, the faster it 
will be to access an element, but the more memory it will use. It's a tradeoff depending of how many elements the map will ultimately 
contains and how fast the random access should be. The default value is 512. This parameter has no impact about the number of elements 
a map can contain. 

</blockquote><p><b>Example:</b> Simple map</p><blockquote>


<pre><font face="Courier New, Courier, mono"size="2">  <b><font color="#006666">NewMap</font></b> <font color="#006666">Country</font>.s()
  
<font color="#006666">  Country</font>("GE") = "Germany"
<font color="#006666">  Country</font>("FR") = "France"
<font color="#006666">  Country</font>("UK") = "United Kingdom"
  
  <b><font color="#006666">Debug</font></b> <font color="#006666">Country</font>("FR")
  
  <b><font color="#006666">ForEach</font></b> <font color="#006666">Country</font>()
    <b><font color="#006666">Debug</font></b> <font color="#006666">Country</font>()
  <b><font color="#006666">Next</font></b>
</font></pre>

</blockquote><p><b>Example:</b> Map as procedure parameter</p><blockquote>


<pre><font face="Courier New, Courier, mono"size="2">  <b><font color="#006666">NewMap</font></b> <font color="#006666">Country</font>.s()
  
<font color="#006666">  Country</font>("GE") = "Germany"
<font color="#006666">  Country</font>("FR") = "France"
<font color="#006666">  Country</font>("UK") = "United Kingdom"

  <b><font color="#006666">Procedure</font></b> <font color="#006666">DebugMap</font>(<b><font color="#006666">Map</font></b> <font color="#006666">ParameterMap</font>.s())

<font color="#006666">    ParameterMap</font>("US") = "United States"

    <b><font color="#006666">ForEach</font></b> <font color="#006666">ParameterMap</font>()
      <b><font color="#006666">Debug</font></b> <font color="#006666">ParameterMap</font>()
    <b><font color="#006666">Next</font></b>
 
  <b><font color="#006666">EndProcedure</font></b>

<font color="#006666">  DebugMap</font>(<font color="#006666">Country</font>())
</font></pre>


</blockquote><p><b>Example:</b> Structured map</p><blockquote>


<pre><font face="Courier New, Courier, mono"size="2">  <b><font color="#006666">Structure</font></b> Car
    Weight.l
    Speed.l
    Price.l
  <b><font color="#006666">EndStructure</font></b>

  <b><font color="#006666">NewMap</font></b> <font color="#006666">Cars</font>.Car()
  
  <font color="#006666">; Here we use the current element after the new insertion</font>
  <font color="#006666">;</font>
<font color="#006666">  Cars</font>("Ferrari F40")\Weight = 1000
<font color="#006666">  Cars</font>()\Speed = 320
<font color="#006666">  Cars</font>()\Price = 500000
  
<font color="#006666">  Cars</font>("Lamborghini Gallardo")\Weight = 1200
<font color="#006666">  Cars</font>()\Speed = 340
<font color="#006666">  Cars</font>()\Price = 700000

  <b><font color="#006666">ForEach</font></b> <font color="#006666">Cars</font>()
    <b><font color="#006666">Debug</font></b> "Car name: "+<font color="#006666">MapKey</font>(<font color="#006666">Cars</font>())
    <b><font color="#006666">Debug</font></b> "Weight: "+<font color="#006666">Str</font>(<font color="#006666">Cars</font>()\Weight)
  <b><font color="#006666">Next</font></b>
 
</font></pre>
</body></html>